import Api from '@/service/api/api';
import { getServiceBaseURL } from '@/utils/service';
import { request } from '../request';

const isHttpProxy = import.meta.env.DEV && import.meta.env.VITE_HTTP_PROXY === 'Y';
const { baseURL, otherBaseURL } = getServiceBaseURL(import.meta.env, isHttpProxy);

/**
 * 查询目录树
 *
 * @param taskId
 */
export function getLogCatalogAction(taskId: number) {
  return request<any>({
    url: `${Api.LogCatalog}?logId=${taskId}`
  });
}

/**
 * 获取标书编辑数据
 *
 * @param taskId
 */
export function getEditDataInfoAction(taskId: number) {
  return request<any>({
    url: `${Api.EditDataInfo}?logId=${taskId}`
  });
}

/**
 * 批量新增目录
 *
 * @param taskId
 * @param params
 */
export function batchInsertCatalogAction(taskId: number, params: any) {
  return request<any>({
    url: `${Api.BatchInsertCatalog}?logId=${taskId}`,
    method: 'post',
    data: params
  });
}

/**
 * 新增目录
 *
 * @param catalogId
 * @param params
 */
export function insertCatalogAction(catalogId: number, params: any) {
  return request<any>({
    url: `${Api.InsertCatalog}?preCatalogId=${catalogId}`,
    method: 'post',
    data: params
  });
}

/**
 * 修改目录
 *
 * @param params
 */
export function updateCatalogAction(params: any) {
  return request<any>({
    url: Api.UpdateCatalog,
    method: 'post',
    data: params
  });
}

/**
 * 删除目录
 *
 * @param params
 */
export function deleteCatalogAction(params: any) {
  return request<any>({
    url: Api.DeleteCatalog,
    method: 'get',
    params
  });
}

/**
 * 新增目录内容
 *
 * @param params
 */
export function insertCatalogDataAction(params: any) {
  return request<any>({
    url: Api.InsertCatalogData,
    method: 'post',
    data: params
  });
}

/**
 * 扩充目录
 *
 * @param parentCatalogId
 * @param params
 */
export function insertChildCatalogAction(parentCatalogId: number, params: any) {
  return request<any>({
    url: `${Api.InsertChildCatalog}?parentCatalogId=${parentCatalogId}`,
    method: 'post',
    data: params
  });
}

/**
 * 查询最近保存的目录内容
 *
 * @param params
 */
export function latestCatalogDataAction(params: any) {
  return request<any>({
    url: Api.LatestCatalogData,
    method: 'get',
    params
  });
}

/**
 * 批量更新目录状态
 *
 * @param params
 */
export function batchUpdateCatalogStatusAction(params: any) {
  return request<any>({
    url: Api.BatchUpdateCatalogStatus,
    method: 'get',
    params
  });
}

/**
 * 章节上移下移
 *
 * @param catalogId
 * @param type 1:上移 2:下移
 */
export function reRankCatalogAction(catalogId: number, type: number) {
  return request<any>({
    url: `${Api.ReRankCatalog}?id=${catalogId}&type=${type}`
  });
}

/**
 * 生成目录
 *
 * @param params
 */
export function getCatalogAction(params: any) {
  return request<any>({
    baseURL: otherBaseURL.algorithmStatus,
    url: Api.GetCatalog,
    method: 'post',
    data: params
  });
}

/**
 * 扩充目录
 *
 * @param params
 */
export function fillCatalogAction(params: any) {
  return request<any>({
    baseURL: otherBaseURL.algorithmStatus,
    url: Api.FillCatalog,
    method: 'post',
    data: params
  });
}

